http = require "http"


http.IncomingMessage::ip = ()->
  if "x-forwarded-for" of @headers
    @headers["x-forwarded-for"]
  else if "x-real-ip" of @headers
    @headers["x-real-ip"]
  else
    @connection.remoteAddress

Array::choice = do ()->
  r = Math.random
  ()->
    @[(r()*@length)|0]
#et = module.exports =
#  ip : (req, res, next)->
#    ip = req.connection.remoteAddress
#    if "x-forwarded-for" of req.headers
#      ip = req.headers["x-forwarded-for"]
#    else if "x-real-ip" of req.headers
#      ip = req.headers["x-real-ip"]
#    req.ip = ip
#    console.log ip
#    next()
